// pages/task/task.js
import dayjs from 'dayjs'
let ds = null
Page({
  data: {
    currentDate: Date.now(),
    showMonthLayer: false,
    year: 2023,
    month: 2,
    minDate: new Date(2023, 5, 1).getTime(),
    maxDate: new Date(2023, 5, 30).getTime(),
  },
  updateM(ds) {
    const year = ds.year()
    const month = ds.month()
    console.log(year, month)
    const minDate = ds.startOf('month').valueOf()
    const maxDate = ds.endOf('month').valueOf()
    this.setData({
      year,
      month,
      minDate,
      maxDate
    })
  },
  nextMonth() {
    ds = ds.add(1, 'month')
    this.updateM(ds)
  },
  lastMonth() {
    ds = ds.subtract(1, 'month')
    this.updateM(ds)
  },
  selectMonth(e) {
    console.log(e.detail, dayjs(e.detail).month())
    this.updateM(dayjs(e.detail))
    this.setData({ showMonthLayer: false })
  },
  showMonthLayer() {
    this.setData({
      currentDate: ds.valueOf(),
      showMonthLayer: true
    })
  },
  closeLayer() {
    this.setData({ showMonthLayer: false })
  },
  onLoad() {
    const year = (new Date()).getFullYear()
    const month = (new Date()).getMonth()
    ds = dayjs().month(month).year(year)
    this.updateM(ds)
  }
})